package com.woniuxy.education.controller;

import com.woniuxy.education.entity.Article;
import com.woniuxy.education.entity.PageResult;
import com.woniuxy.education.entity.SelectArticle;
import com.woniuxy.education.service.ArticleService;
import com.woniuxy.education.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author author
 * @create 2021/4/2
 */
@CrossOrigin
@RestController
@RequestMapping("/gradedean")
public class ArticleController {
    @Autowired
    ArticleService articleService;

    //添加文章
    @RequestMapping("/addArticle")
    protected boolean addArticle(@RequestBody Article article) {
        System.out.println(article);
        return articleService.addArticle(article);
    }

    //文章查询
    @RequestMapping("/allArticle")
    protected PageResult<Article> AllArticle(@RequestBody SelectArticle selectArticle) {
        System.out.println(selectArticle);
        return articleService.findArticleByPage(selectArticle);
    }

    //多条件查询
//    @RequestMapping ("/ifArticle")
//    @ResponseBody
//    protected PageResult<Article> ifArticle(int page,int size,Integer state,Integer type, String article_name) {
//
//        return articleService.findByIf(page, size, state, type, article_name);
//    }

    //修改文章状态已通过
    @RequestMapping("/Onestate")
    @ResponseBody
    protected ResponseResult<String> updateOneState(int id) {

        ResponseResult<String> responseResult = new ResponseResult<>();
        if (articleService.updateOneState(id)) {
            responseResult.setCode(200);
            responseResult.setMessage("操作成功");
            return responseResult;
        } else {
            responseResult.setCode(500);
            responseResult.setMessage("请检查后再次操作");
            return responseResult;
        }
    }
        //修改文章状态未通过
        @RequestMapping("/Twostate")
        @ResponseBody
        protected ResponseResult<String> updateTwostate ( int id) {

            ResponseResult<String> responseResult = new ResponseResult<>();
            if (articleService.updateTwoState(id)) {

                responseResult.setCode(200);
                responseResult.setMessage("操作成功");
                return responseResult;

            } else {
                responseResult.setCode(500);
                responseResult.setMessage("请检查后再次操作");
                return responseResult;
            }
        }

    }
